Fix tab ID becoming 0 once the tab contains splits - #4208
Conversation
`Tab` embeds its root `views.Node`, so `tab:ID()` from Lua resolved to `Node.ID()`, which returns 0 for any node that has children. As soon as a tab contained a split its root stopped being a leaf and the id was gone. Give `Tab` its own id, taken from the root node when the tab is created, so it stays the same after splitting. An unsplit tab reports the same value as before.
| // id is this tab's unique id. It is taken from the root node when the | ||
| // tab is created and does not change afterwards, unlike the id of the | ||
| // embedded root node, which becomes 0 once the node has children. | ||
| id uint64 |
There was a problem hiding this comment.
I'm unsure, if we really need to add a further id within the tab, which is already a view, instead of taking care of this:
micro/internal/views/splits.go
Lines 53 to 55 in 393cf24
micro/internal/views/splits.go
Lines 92 to 98 in 393cf24
There was a problem hiding this comment.
Fair point. 1af86dd drops the extra field and lets Node.ID() return n.id for containers too; a node that gets split keeps its id and hands it to the child taking its place, so GetNode() still resolves to the same leaf and only the 0 for non-leaf nodes goes away. One thing to be aware of: flatten() copies the last remaining child over the root, so once the pane a tab was created with is closed while another pane is left, the tab id becomes that pane's id (a root leaf has to carry the id of its only pane for GetNode() to find it, so I don't see a way around that within views); if that case matters I'd rather go back to the tab-level id.
`Node.ID()` returned 0 for any node with children. A tab embeds its root node, so `tab:ID()` in Lua dropped to 0 as soon as the tab was split. A node that gets split keeps its id and hands the same id to the child that takes its place, so returning it from a container does not change which leaf `GetNode()` finds. Drop the extra id on `Tab` from the previous commit and test this in views instead.
|
@Neko-Box-Coder: |
|
With this change applied, when a split happens, wouldn't there be 2 nodes (tab parent node and the split node) with the same ID? If so, I don't think this should happen. [Edit]: |
|
Yes, after a split the container node and its first child hold the same id, but this change doesn't create that. Here is The only thing that differs is I did try the alternative of giving the container a fresh id so the ids stay unique, and it costs more than the bug is worth: the pane that was already there keeps splitID 1, |
|
Thanks for your reply, I appreciate your graph and in-depth explanations.
Hm... while I understand what you are saying, I am kinda iffy about having nodes not having a unique ID tbh. Previously if a lua end user wants to iterate/track buffer nodes, they can just store the IDs that are non-zero. With this change, however, they now would need to do an additional check to see if the node is leaf or not. That being said, I am not aware of any plugins that rely on the node ID afaik.
If you just need to have an unique Id for tracking tabs in lua, would storing the tab pointers themselves work? I think they are persistent. |
Tabembeds its rootviews.Node, sotab:ID()in Lua ends up callingNode.ID(). That method returns 0 for any node that has children, and once a tab contains a split its root is no longer a leaf. A plugin that keys anything on the tab id loses track of the tab the moment the user splits it, which is what #4186 reports.Tabnow carries its own id, taken from the root node when the tab is created, andID()returns that. For an unsplit tab the value is the same as before, it just no longer changes after a split. A small test ininternal/actioncovers the split case and checks that two tabs get distinct ids.Fixes #4186